<template>
  <el-row>
    <el-col :span="24">
      <el-card>
        <el-form ref="searchForm" class="el-form-col search-form" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="code">
                <el-input v-model="search.code" placeholder="拣货单号"></el-input>
              </el-form-item>
            </el-col>
            <!--<el-col style="position: absolute" :span = "6" v-if="searchOpen" >-->
              <!--<el-form-item label="拣货单号:" prop="code">-->
                <!--<el-input type="textarea" :rows="4" v-model="search.code"></el-input>-->
              <!--</el-form-item>-->
            <!--</el-col>-->
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderNo">
                <el-input v-model="search.orderNo" placeholder="关联单号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="warehouseId">
                <el-select v-model="search.warehouseId" placeholder="请选择入库仓">
                  <el-option v-for="item in warehouseIdArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-lg-only hidden-xl-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="12">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button @click="reset('searchForm')" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="inputWarehouseNo">
                <el-input v-model="search.inputWarehouseNo" placeholder="入库单号"></el-input>
              </el-form-item>

            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="cargoOwner">
                <el-input v-model="search.cargoOwner" placeholder="商家名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-md-only hidden-sm-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="12">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button @click="reset('searchForm')" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="sortingPersonName">
                <el-input v-model="search.sortingPersonName" placeholder="拣货员"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="allocationName">
                <el-input v-model="search.allocationName" placeholder="分配人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item  prop="allocationStartTime">
                <el-date-picker type="date"
                                placeholder="分配开始时间"
                                value-format="yyyy-MM-dd"
                                v-model="search.allocationStartTime" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="allocationEndTime">
                <el-date-picker type="date"
                                placeholder="分配结束时间"
                                v-model="search.allocationEndTime"
                                value-format="yyyy-MM-dd"
                                :picker-options="{disabledDate}" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </el-col>

    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/inPutWarehouse/getSortingFormList"
        :columns="columns"
      >
        <template slot="preColumn">
          <el-table-column prop="orderNo" fixed="left" width="170px" align="center" label="关联单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="show1(scope.row)">{{ scope.row.orderNo }}</a>
            </template>
          </el-table-column>
          <el-table-column prop="orderNo" fixed="left" width="170px" align="center" label="入库单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="show(scope.row)">{{ scope.row.inputWarehouseNo }}</a>
            </template>
          </el-table-column>
        </template>
        <template slot="column">
          <el-table-column fixed="right" width="80px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="show(scope.row)"
              ><span>详情</span></el-button>
              <el-button
                size="mini"
                type="text"
                @click="print(scope.row)"
              ><span>打印</span></el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
    <Print-modal ref="PrintModal" :sortingId="sortingId"></Print-modal>
  </el-row>
</template>
<script>
import {copy} from '@/utils'
import {unixTimestampFilter, filterDataBaseDictionary} from '@/filters'
import {getAllWarehouse} from '@/utils/selectOptions'
import moment from 'moment'
import PrintModal from '@/views/oms/enterWarehouse/warehousePicklist/PrintModal'
export default {
  name: 'enterWarehousePicklistIndex',
  components: {
    PrintModal
  },
  data() {
    return {
      search: {
        orderNo: '',
        inputWarehouseNo: '',
        warehouseId: '',
        sortingPersonName: '',
        cargoOwner: '',
        allocationName: '',
        code: '',
        allocationStartTime: '',
        allocationEndTime: '',
        consignePhone: '',
        consigneName: ''
      },
      searchOpen: false,
      searchLoading: false,
      warehouseIdArr: [],
      sortingId: '',
      columns: [
        {label: '用户姓名', data: 'consigneName'},
        {label: '用户电话', data: 'consignePhone'},
        {
          label: '入库仓',
          data: 'warehouse',
          render(data, type, full, meta) {
            return filterDataBaseDictionary(data)
          }
        },
        {label: '商家名称', data: 'cargoOwner'},
        {label: '拣货单号', data: 'code'},
        {
          label: '总体积(m³)',
          data: 'totalVolume'
        },
        {
          label: '包件数',
          data: 'packageNum'
        },
        {
          label: '拣货员',
          data: 'sortingPersonName'
        },
        {
          label: '分配人',
          data: 'allocationName'
        },
        {
          label: '分配时间',
          data: 'allocationTime',
          render(data, type, full, meta) {
            return unixTimestampFilter(data)
          }
        }
      ]
    }
  },
  created() {
    getAllWarehouse().then(arr => {
      this.warehouseIdArr = arr
    })
  },
  methods: {
    show(data) {
      this.$router.push({path: '/ss-oms/enterWarehouse/warehouse-picklist/show/' + data.sortingId})
    },
    show1(data) {
      this.$router.push({path: '/ss-oms/enterWarehouse/warehousing-order/show/' + data.id})
    },
    disabledDate(time) {
      return time.getTime() < moment(this.search.allocationStartTime).format('x')
    },
    searchFunc(search) {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    reset() {
      this.$refs.searchForm.resetFields()
    },
    refresh() {
      this.searchFunc(this.search)
    },
    print(data) {
      this.sortingId = data.sortingId
      this.$refs.PrintModal.show()
    }
  }
}
</script>
